<?php

ini_set('display_errors', 1);
ini_set('memory_limit', -1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\trade\Order as mOrder;
use Biz\model\trade\OrderGoods as mOrderGoods;
use Doraemon\amqp\Queue;


$startTime = date('Y-m-d H:i:s',strtotime('-1 days'));

$orderList = mOrder::select('*',['addtime[>]'=>$startTime]);

foreach ($orderList as $orderInfo) {

    $orderGoods = mOrderGoods::select('*', ['order_no' => $orderInfo['order_no']]);

    $payAmount = array_sum(array_column($orderGoods, 'pay_amount'));
    $payAmount = $payAmount + $orderInfo['shipping_amount'];

    //比对pay_amount是否有错
    if(bccomp($orderInfo['pay_amount'],$payAmount,2) != 0){
        sendMsg(vsprintf("订单信息出错：订单支付金额报警 order_no:%s,订单表pay_amount:%s,实际计算pay_amount%s",[
            $orderInfo['order_no'],
            $orderInfo['pay_amount'],
            $payAmount
        ]));
    }




}

function sendMsg($content){
    Queue::insertQueue("queue/Wechatnotice/toTag", [
        "totag"=>\Biz\pockets\constInterface\BizWechatTagConfig::TAG_BIZ_RD_SYSTEM,
        "content" => $content
    ], Queue::QUEUE_BIZ);
}